package com.kdfly.zmdfsj.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kdfly.zmdfsj.R;
import com.kdfly.zmdfsj.entity.Store;
import com.kdfly.zmdfsj.model.Constants;

import java.util.List;

/**
 * Created by Sean on 2016/3/28.
 */
public class storeAdapter extends BaseAdapter{

    private List<Store> mLists;
    private Context mContext;

    LayoutInflater inflater;

    public storeAdapter(Context context, List<Store> lists){
        this.mContext = context;
        this.mLists = lists;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mLists.size();
    }

    @Override
    public Object getItem(int arg0) {
        return mLists.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder holder = null;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = inflater.inflate(R.layout.listitem_store, null,false);
            holder.goodName = (TextView) convertView.findViewById(R.id.goodName);
            holder.goodPrice = (TextView) convertView.findViewById(R.id.goodPrice);
            holder.goodid = (TextView) convertView.findViewById(R.id.goodid);
            convertView.setTag(holder);
        }else {
            holder = (viewHolder) convertView.getTag();
        }
        holder.goodName.setText(mLists.get(position).getName());
        holder.goodPrice.setText(mLists.get(position).getPrice() + "");
        holder.goodPrice.setTextColor(Color.parseColor("#755A27"));
        if (mLists.get(position).getPrice() < Constants.goodsPriceBase[mLists.get(position).getId()] + Constants.goodsPriceRand[mLists.get(position).getId()]/4){
            holder.goodPrice.setTextColor(Color.GREEN);
        }
        holder.goodid.setText(mLists.get(position).getId() + "");
        return convertView;
    }

    public class viewHolder {
        private TextView goodName;
        private TextView goodPrice;
        private TextView goodid;
    }
}
